package com.example.mybaties.testone.aop.advice;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.aop.ThrowsAdvice;

import java.lang.reflect.Method;

/**
 * 抛出异常时进行增强
 */
public class ThrowAdvice implements ThrowsAdvice {

    private Logger logger = LogManager.getLogger(this.getClass());

    /**
     * 注意事项
     * 1, 名字必须是下面这个，不能改动
     * 2, 参数要么像下面这样，要么只有最后一个，就这2种选择，没有其他选择
     */
    public void afterThrowing(Method method, Object[] args, Object target, Exception ex) {
        logger.debug(method.getName() + "抛出了异常，异常信息为：" + ex.getMessage());
        logger.debug("对事物进行了回滚");
    }

}
